const { PythonShell } = require('python-shell');

// let pyshell = new PythonShell('/Users/q/Desktop/YOLO/test.py');

async function YOLO(image_path) {
  return new Promise((resolve, reject) => {
    let options = {
      mode: 'text',
      pythonPath: '/usr/bin/python3',
      pythonOptions: ['-u'],
      scriptPath: './',
      args: [image_path]
    };

    let pyshell = new PythonShell('../YOLO/yolov8.py', options);
    let result = [];
    pyshell.on('message', function (message) {
      console.log(message);
      if (message.includes('result:')) {
        result.push(message.split(':')[1]);
      }
    });

    pyshell.end(function (err, code, signal) {
      if (err) {
        console.error('Python脚本错误:', err);
        reject(err);
      }
      console.log('Python脚本完成');
      resolve(result);
    });
  });
}

module.exports = {
  YOLO
}
